﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySpace.Data;

/// <summary>
///AdminTable类封装管理员数据表
/// </summary>
namespace DataBaseTable
{
    public class AdminTable : DBTable
    {
        private const string tableName="admin";
        public AdminTable()
            : base(GetHandler.Init(), tableName)
        {
            this.GetRow();
        }
        public AdminTable(string UserName)
            : base(GetHandler.Init(), tableName)
        {
            this.Filter = "User_Name=?";
            this.AddParameter("User_Name", UserName);
            this.GetRow();
        }
        public AdminTable(int Userid)
            : base(GetHandler.Init(), tableName)
        {
            this.Filter="id=?";
            this.AddParameter("id", Userid);
            this.GetRow();
        }
        /// <summary>
        /// ID
        /// </summary>
        public int ID
        {
            get
            {
                try { return (int)this.DataRow["id"]; }
                catch { return 0; }
            }
        }
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName
        {
            get
            {
                try { return (string)this.DataRow["User_Name"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["User_Name"] = value;
            }
        }
        /// <summary>
        /// 管理员名称
        /// </summary>
        public string TureName
        {
            get
            {
                try { return (string)this.DataRow["Ture_Name"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["Ture_Name"] = value;
            }
        }
        /// <summary>
        /// 用户角色
        /// </summary>
        public string UserRole
        {
            get
            {
                try { return (string)this.DataRow["User_Role"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["User_Role"] = value;
            }
        }
        /// <summary>
        /// 用户密码
        /// </summary>
        public string UserPassword
        {
            get
            {
                try { return (string)this.DataRow["User_Password"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["User_Password"] = value;
            }
        }
        /// <summary>
        /// 用户添加时间
        /// </summary>
        public DateTime AddTime
        {
            get
            {
                try { return (DateTime)this.DataRow["Add_Time"]; }
                catch { return DateTime.Now; }
            }
        }
        public static bool UserIsExist(string UserName)
        {
            if((new AdminTable(UserName)).ID==0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public static bool UserIsExist(int Userid)
        {
            if ((new AdminTable(Userid)).ID == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }


    }
}